package com.example.tao_city.text1;

import android.os.Bundle;
import android.os.Handler;
import android.renderscript.RenderScript;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by TAO_CITY on 2018/1/16.
 */

public class Chaxun_tieka extends Fragment {
    private View mv,singel1,singel2,singel3;
    private Handler hand;
    private boolean tuichu=true;
    private int i=1;
    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
        mv=inflater.inflate(R.layout.chaxun_tieka,container,false);
        initbutton();

        return mv;
    }
    private void initbutton(){
        singel1= mv.findViewById(R.id.tieka_singel1);
        singel2= mv.findViewById(R.id.tieka_singel2);
        singel3= mv.findViewById(R.id.tieka_singel3);
    }

    @Override
    public void onResume() {
        super.onResume();
        tuichu=true;
        i=1;
        hand=new Handler();
        hand.postDelayed(runnable,1000);
    }

    @Override
    public void onPause() {
        tuichu=false;
        super.onPause();
    }

    Runnable runnable=new Runnable() {
        @Override
        public void run() {
            if(tuichu) {
                if (Fm1_Chaxun.runing) {
                    setview();
                    switch (i) {
                        case 1:
                            singel1.setVisibility(View.VISIBLE);
                            break;
                        case 2:
                            singel2.setVisibility(View.VISIBLE);
                            break;
                        case 3:
                            singel3.setVisibility(View.VISIBLE);
                            break;
                    }
                   i++;
                    if (i == 4) {
                        i = 0;
                    }
                }else {
                    setview();
                    i=1;
                }
                hand.postDelayed(this, 1000);
            }
        }
    };
    private void setview(){
        singel1.setVisibility(View.INVISIBLE);
        singel2.setVisibility(View.INVISIBLE);
        singel3.setVisibility(View.INVISIBLE);
    }

}
